package com.itheima.spring.aop;

import com.itheima.spring.aop.advisor.Advisor;
import com.itheima.spring.beans.BeanFactory;

import java.util.List;

public class DefaultAopProxyFactory implements AopProxyFactory {


    @Override
    public AopProxy createAopProxy(Object bean, String beanName, List<Advisor> matchAdvisors, BeanFactory beanFactory) throws Throwable {

        // 是该用jdk动态代理还是cglib
        if(shouldUseJDKDynamicProxy(bean,beanName)){
            return new JdkDynamicAopProxy(bean,beanName,matchAdvisors,beanFactory);
        }else{
            return new CglibDynamicAopProxy(bean,beanName,matchAdvisors,beanFactory);
        }
    }

    //默认使用cglib
    private boolean shouldUseJDKDynamicProxy(Object bean, String beanName) {
        // 如何判断？
        // 这样可以吗：有实现接口就用JDK,没有就用cglib？
        return false;
    }
}
